import { Component, OnInit ,ViewChild } from '@angular/core';
import { CommonService } from '../../service/common.service';

//引入接受路由传值的模块
import { ActivatedRoute, Router } from '@angular/router';

@Component({
  selector: 'app-mymill',
  templateUrl: './mymill.page.html',
  styleUrls: ['./mymill.page.scss'],
})
export class MymillPage implements OnInit {
  @ViewChild('slides') slides;

  public segmentAModel:string = 's1';
  public addearnings:number = 0
  public addstore:number = 0
  public earningslist:any[] = []
  public firendlist:any[] = [];
  public name:string = 'fil'

  constructor(private common:CommonService,private activatedRoute:ActivatedRoute) { }

  ngOnInit() {
    //接受路由传值过来的图片路径
    this.activatedRoute.queryParams.subscribe((data: any) => {
      this.name = data.name
    })

    this.summaryData()
    this.summaryDatat()
    this.incomeDetails()
    this.firendList()
  }

  // 切换
  ontabs(value:any){
    let index:any;
    if(value == 's1'){
      index = 0
    }
    if(value == 's2'){
      index = 1
    }
    this.slides.slideTo(index,300)
  }
  // 滑动切换
  slideChange(){
    this.slides.getActiveIndex().then( Number =>{
      // console.log(Number)
      if(Number == 0){
        this.segmentAModel = 's1'
      }
      if(Number == 1){
        this.segmentAModel = 's2'
      }
      // this.slidesA.el.scrollTop= 0
    })
  }


  // 累计收益
  summaryData(){
    var api = '/tbr/assets/summaryData?coinType='+this.name+'&type=0'
    this.common.get(api).then((res:any)=>{
      if(res.code == 200){
        this.addearnings = res.data
      }
    })
  }
  // 累计收益
  summaryDatat(){
    var api = '/tbr/assets/summaryData?coinType='+this.name+'&type=1'
    this.common.get(api).then((res:any)=>{
      if(res.code == 200){
        this.addstore = res.data
      }
    })
  }
  // 获取金币收益明细
  incomeDetails(){
    var api = '/tbr/assets/incomeDetails?coinType='+this.name+'&page=1&size=500'
    this.common.get(api).then((res:any)=>{
      if(res.code == 200){
        this.earningslist = res.data.records
      }
    })
  }

  // 获取金币业绩明细t
  // 好友列表
  firendList(){
    var api = '/tbr/getMyFriend?coinType='+this.name
    var params = {
      userId:this.common.getInfo().userId,
      page:1,
      limit:200
    }
    this.common.post(api,params,false).then((res:any)=>{
      // console.log('好友列表')
      // console.log(res)
      if(res.code == 200){
        this.firendlist = res.data.records

        for(var i = 0;i< this.firendlist.length;i++){
          if(this.firendlist[i].avater == '' || this.firendlist[i].avater == null){
            this.firendlist[i].avater="assets/avater.png"
          }
        }

      }
    })
  }

}
